昨天有講解過如何在 Popup 裡面新增想要顯示的內容,今天要實作 Popup 上新增能夠切換內容的元件。
準備一個 PopupTabs.vue 裡面有 Map 和 IntroduceBox 元件 ,IntroduceBox 元件用來顯示內容。
<Map :dom="dom" />
import Map from "./Map.vue";
const dom = ref(null);
const props = defineProps({
dom: Object,
});
watch(
() => props.dom,
(newDom) => {
marker.bindPopup(newDom);
}
);
<IntroduceBox
:currentName="currentName"
:introduceData="introduceData"
@getDom="getDom"
/>
const currentName = ref("tab");
const introduceData = reactive([
{
name: "tab",
img: "https://picsum.photos/id/684/600/400",
content: "Ipsum ratione nulla iure rem tempora, quasi quis minima consequatur",
},
{
name: "tab2",
img: "https://picsum.photos/id/685/600/400",
content: "Lorem ipsum, dolor sit amet consectetur adipisicing elit",
},
]);
const getDom = (boxDom) => {
dom.value = boxDom;
};
const props = defineProps({
introduceData: Array,
currentName: String,
});
const emit = defineEmits(["getDom"]);
const dom = ref(null);
onMounted(() => {
emit("getDom", dom.value);
});
範例完成:
範例連結:
https://github.com/XuanCbbLin/Vue3-leaflet/tree/master/src/components/PopupTabs